import logging
from datetime import timedelta
from redis import StrictRedis


class Config(object):
    """基础配置类"""
    # 1.设置调试模式为True
    DEBUG = True

    # 2.设置密钥
    SECRET_KEY = 'asdfsadfasd'

    # 3.设置mysql配置信息
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:root@localhost:3306/home'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 4.设置事务自动提交,在视图函数结束的时候自动提交
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # 5.设置redis配置信息
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # 6.设置session信息
    SESSION_TYPE = 'redis'
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    SESSION_USE_SIGNER = True
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)

    # 7.定义默认日志级别
    LEVEL_NAME = logging.DEBUG

class DevelopConfig(Config):
    """开发模式"""
    pass

class ProductConfig(Config):
    """线上模式"""
    DEBUG = False
    LEVEL_NAME = logging.ERROR

class TestConfig(Config):
    """测试模式"""
    pass

# 配置接口字典
config_dict = {
    'develop':DevelopConfig,
    'product':ProductConfig,
    'test':TestConfig
}
